from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-25 14:02:08.569341
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 25, Jun, 2022
Time: 14:02:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5880
Nobs: 698.000 HQIC: -49.9477
Log likelihood: 8687.12 FPE: 1.61999e-22
AIC: -50.1745 Det(Omega_mle): 1.42532e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299530 0.057901 5.173 0.000
L1.Burgenland 0.107580 0.038021 2.829 0.005
L1.Kärnten -0.109455 0.020120 -5.440 0.000
L1.Niederösterreich 0.213013 0.079416 2.682 0.007
L1.Oberösterreich 0.103274 0.077939 1.325 0.185
L1.Salzburg 0.257114 0.040693 6.318 0.000
L1.Steiermark 0.045142 0.052968 0.852 0.394
L1.Tirol 0.109705 0.042992 2.552 0.011
L1.Vorarlberg -0.058878 0.037312 -1.578 0.115
L1.Wien 0.038277 0.068985 0.555 0.579
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.050227 0.121477 0.413 0.679
L1.Burgenland -0.034296 0.079769 -0.430 0.667
L1.Kärnten 0.041345 0.042213 0.979 0.327
L1.Niederösterreich -0.169038 0.166617 -1.015 0.310
L1.Oberösterreich 0.425796 0.163519 2.604 0.009
L1.Salzburg 0.289161 0.085375 3.387 0.001
L1.Steiermark 0.100650 0.111128 0.906 0.365
L1.Tirol 0.318474 0.090197 3.531 0.000
L1.Vorarlberg 0.028118 0.078281 0.359 0.719
L1.Wien -0.043076 0.144731 -0.298 0.766
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186109 0.029648 6.277 0.000
L1.Burgenland 0.090443 0.019469 4.646 0.000
L1.Kärnten -0.007987 0.010303 -0.775 0.438
L1.Niederösterreich 0.265759 0.040666 6.535 0.000
L1.Oberösterreich 0.136604 0.039909 3.423 0.001
L1.Salzburg 0.045531 0.020837 2.185 0.029
L1.Steiermark 0.020440 0.027123 0.754 0.451
L1.Tirol 0.091571 0.022014 4.160 0.000
L1.Vorarlberg 0.056485 0.019106 2.956 0.003
L1.Wien 0.116334 0.035324 3.293 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111558 0.030094 3.707 0.000
L1.Burgenland 0.045198 0.019761 2.287 0.022
L1.Kärnten -0.013724 0.010457 -1.312 0.189
L1.Niederösterreich 0.190225 0.041276 4.609 0.000
L1.Oberösterreich 0.304595 0.040508 7.519 0.000
L1.Salzburg 0.107153 0.021150 5.066 0.000
L1.Steiermark 0.104644 0.027530 3.801 0.000
L1.Tirol 0.103198 0.022345 4.618 0.000
L1.Vorarlberg 0.068227 0.019393 3.518 0.000
L1.Wien -0.021883 0.035854 -0.610 0.542
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134794 0.055087 2.447 0.014
L1.Burgenland -0.051154 0.036173 -1.414 0.157
L1.Kärnten -0.044271 0.019142 -2.313 0.021
L1.Niederösterreich 0.156682 0.075556 2.074 0.038
L1.Oberösterreich 0.139067 0.074151 1.875 0.061
L1.Salzburg 0.285614 0.038715 7.377 0.000
L1.Steiermark 0.048117 0.050394 0.955 0.340
L1.Tirol 0.167273 0.040902 4.090 0.000
L1.Vorarlberg 0.093242 0.035498 2.627 0.009
L1.Wien 0.073028 0.065632 1.113 0.266
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054151 0.043767 1.237 0.216
L1.Burgenland 0.037467 0.028740 1.304 0.192
L1.Kärnten 0.051093 0.015209 3.359 0.001
L1.Niederösterreich 0.217407 0.060030 3.622 0.000
L1.Oberösterreich 0.294483 0.058914 4.999 0.000
L1.Salzburg 0.047239 0.030759 1.536 0.125
L1.Steiermark 0.001968 0.040038 0.049 0.961
L1.Tirol 0.140605 0.032497 4.327 0.000
L1.Vorarlberg 0.073981 0.028204 2.623 0.009
L1.Wien 0.082496 0.052145 1.582 0.114
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175935 0.052376 3.359 0.001
L1.Burgenland -0.002396 0.034393 -0.070 0.944
L1.Kärnten -0.063082 0.018200 -3.466 0.001
L1.Niederösterreich -0.080216 0.071838 -1.117 0.264
L1.Oberösterreich 0.193426 0.070502 2.744 0.006
L1.Salzburg 0.056609 0.036810 1.538 0.124
L1.Steiermark 0.236241 0.047913 4.931 0.000
L1.Tirol 0.497903 0.038889 12.803 0.000
L1.Vorarlberg 0.044312 0.033751 1.313 0.189
L1.Wien -0.056209 0.062402 -0.901 0.368
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167838 0.059490 2.821 0.005
L1.Burgenland -0.012786 0.039064 -0.327 0.743
L1.Kärnten 0.063952 0.020672 3.094 0.002
L1.Niederösterreich 0.204261 0.081596 2.503 0.012
L1.Oberösterreich -0.074757 0.080078 -0.934 0.351
L1.Salzburg 0.211161 0.041810 5.051 0.000
L1.Steiermark 0.127069 0.054421 2.335 0.020
L1.Tirol 0.065922 0.044171 1.492 0.136
L1.Vorarlberg 0.118699 0.038336 3.096 0.002
L1.Wien 0.131119 0.070878 1.850 0.064
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.363996 0.034449 10.566 0.000
L1.Burgenland 0.006977 0.022621 0.308 0.758
L1.Kärnten -0.023513 0.011971 -1.964 0.050
L1.Niederösterreich 0.215753 0.047250 4.566 0.000
L1.Oberösterreich 0.204742 0.046371 4.415 0.000
L1.Salzburg 0.043839 0.024211 1.811 0.070
L1.Steiermark -0.015092 0.031514 -0.479 0.632
L1.Tirol 0.105685 0.025578 4.132 0.000
L1.Vorarlberg 0.069667 0.022199 3.138 0.002
L1.Wien 0.030213 0.041043 0.736 0.462
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037804 0.137081 0.194165 0.155814 0.114693 0.102140 0.058688 0.216824
Kärnten 0.037804 1.000000 -0.014868 0.134125 0.056172 0.095490 0.435984 -0.053227 0.093364
Niederösterreich 0.137081 -0.014868 1.000000 0.336590 0.143409 0.294614 0.092046 0.176934 0.311703
Oberösterreich 0.194165 0.134125 0.336590 1.000000 0.228958 0.325101 0.176692 0.162936 0.264870
Salzburg 0.155814 0.056172 0.143409 0.228958 1.000000 0.139015 0.117938 0.140993 0.131305
Steiermark 0.114693 0.095490 0.294614 0.325101 0.139015 1.000000 0.145566 0.129106 0.073358
Tirol 0.102140 0.435984 0.092046 0.176692 0.117938 0.145566 1.000000 0.113157 0.141249
Vorarlberg 0.058688 -0.053227 0.176934 0.162936 0.140993 0.129106 0.113157 1.000000 0.004771
Wien 0.216824 0.093364 0.311703 0.264870 0.131305 0.073358 0.141249 0.004771 1.000000